<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>盘点货物信息</title>
		<!-- Tell the browser to be responsive to screen width -->
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!-- Font Awesome -->
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
		<!-- Ionicons -->
		<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
		<!-- Theme style -->
		<link rel="stylesheet" href="../../dist/css/adminlte.min.css">

		<!-- Google Font: Source Sans Pro -->
		<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
	</head>

	<body class="hold-transition sidebar-mini">

		<!-- Main content -->
		<section class="content">
			<div class="container-fluid">
				<div class="row">
					<div class="col-md-9">
						<!-- Bar chart -->
						<!-- Donut chart -->
						<div class="card card-primary card-outline">
							<div class="card-header">
								<h3 class="card-title">
                  <i class="fa fa-bar-chart-o"></i>
                                               库存余量百分比
                </h3>

								<div class="card-tools">
									<button type="button" class="btn btn-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                  </button>
									<!--		<button type="button" class="btn btn-tool" data-widget="remove"><i class="fa fa-times"></i>
                  </button>-->
								</div>
							</div>
							<div class="card-body">
								<div id="donut-chart" style="height: 300px;" align="center"></div>
							</div>
							<!-- /.card-body-->
						</div>

						<!-- /.card -->
					</div>
					<!-- /.col -->
					<div class="col-md-3">
						<!-- Bar chart -->
						<!-- Donut chart -->
						<div class="card card-primary card-outline">
							<div class="card-header">
								<h3 class="card-title">
                            <i class="fa fa-bar-chart-o"></i>
                                                                            功能区
                                </h3>

								<div class="card-tools">
									<button type="button" class="btn btn-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                  </button>
									<!--		<button type="button" class="btn btn-tool" data-widget="remove"><i class="fa fa-times"></i>
                  </button>-->
								</div>
							</div>
							<div class="card-body">
								<button type="button" onclick="goodsRequiringTransit()" class="btn btn-block btn-success btn-lg">查看需中转货物</button>
								<hr />
								<button type="button" onclick="goodsToBeShipped()"  class="btn btn-block btn-info btn-lg">查看需装运货物</button>
								<hr />
								<button type="button" onclick="whole()"  class="btn btn-block btn-secondary btn-lg">查看仓库内所有货物信息</button>
                                <hr />
                               <table>
                                	<tr>
                                    <td>
                                  <button type="button" onclick="addTransitofsingle()" id="bu1" class="btn btn-block btn-default btn-lg">添加到中转单</button>
                                    </td> 
                                    <td>
                                    	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    </td>
                                    <td >
                                  <button type="button" onclick="addTloading()" id="bu2" class="btn btn-block btn-default btn-lg">添加到装运单</button>
                                    </td> 
                                	</tr>
                                </table>
								
							</div>
							<!-- /.card-body-->
						</div>

						<!-- /.card -->
					</div>
					<!-- /.col -->
				</div>
				<!--数据显示区-->
						<section class="content">
			<div class="row">
				<div class="col-12">
					<div class="card">
						<div class="card-header">
							<h3 class="card-title"><b id="txt"></b></h3>
						</div>
						<!-- /.card-header -->
						<div class="card-body">
							<table id="example2" class="table table-bordered table-hover">
								<thead>
									<tr>
										<th>货物编号</th>
										<th>出发日期</th>
										<th>是否被签收</th>
										<th>目的地</th>
										<th>距离目的地还有</th>
									</tr>
								</thead>
								<tbody id="windows" >

								</tbody>
								<tfoot>
									<tr>
										<th>货物编号</th>
										<th>出发日期</th>
										<th>是否被签收</th>
										<th>目的地</th>
										<th>距离目的地还有</th>
									</tr>
								</tfoot>
							</table>
						</div>
						<!-- /.card-body -->
					</div>
					<!-- /.card -->
					<!-- /.card -->
				</div>
				<!-- /.col -->
			</div>
			<!-- /.row -->
		</section>
		<!-- /.content -->
				<!-- /.row -->
			</div>
			<!-- /.container-fluid -->
		</section>

		<!-- Control Sidebar -->
		<aside class="control-sidebar control-sidebar-dark">
			<!-- Control sidebar content goes here -->
		</aside>
		<!-- /.control-sidebar -->

		<!-- jQuery -->
		<script src="../../plugins/jquery/jquery.min.js"></script>
		<!-- Bootstrap 4 -->
		<script src="../../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
		<!-- FastClick -->
		<script src="../../plugins/fastclick/fastclick.js"></script>
		<!-- AdminLTE App -->
		<script src="../../dist/js/adminlte.min.js"></script>
		<!-- AdminLTE for demo purposes -->
		<script src="../../dist/js/demo.js"></script>
		<!-- FLOT CHARTS -->
		<script src="../../plugins/flot/jquery.flot.min.js"></script>
		<!-- FLOT RESIZE PLUGIN - allows the chart to redraw when the window is resized -->
		<script src="../../plugins/flot/jquery.flot.resize.min.js"></script>
		<!-- FLOT PIE PLUGIN - also used to draw donut charts -->
		<script src="../../plugins/flot/jquery.flot.pie.min.js"></script>
		<!-- FLOT CATEGORIES PLUGIN - Used to draw bar charts -->
		<script src="../../plugins/flot/jquery.flot.categories.min.js"></script>
	    <script src="../../js/jquery.cookie.js"></script>

		<!-- Page script -->
		<script>
			$.ajax({
				type: "post", //请求方式
				async: true, //是否异步
				xhrFields: {
					withCredentials: true
				},
				crossDomain: true,
				url: "http://localhost:8073/show_transferstation_transit_warehouses",
				dataType: "json", //跨域json请求一定是jsonp
				// jsonp: "callback", //跨域请求的参数名，默认是callback
				//jsonpCallback:"successCallback",    //自定义跨域参数值，回调函数名也是一样，默认为jQuery自动生成的字符串
				data: {
					sid: $.cookie("sid")
				}, //请求参数
				beforeSend: function() {
					//请求前的处理
					//alert("请求前")
				},
				success: function(data) {
					var donutData = []
					if(data.length){
					$.each(data, function(i, d) {
						donutData[i] = {
							label: d.region + 'A区',
							data: d.space / d.gross * 100,
							color: "#f529" + i + "" + i + ""
						}
					})

					$.plot('#donut-chart', donutData, {
						series: {
							pie: {
								show: true,
								radius: 1,
								innerRadius: 0.5,
								label: {
									show: true,
									radius: 2 / 3,
									formatter: labelFormatter,
									threshold: 0.1
								}

							}
						},
						legend: {
							show: false
						}
					})
					}else{
						$("#donut-chart").append("<h2>仓库内无货物</h2>")
					}

				}
			});

			function labelFormatter(label, series) {
				return '<div style="font-size:13px; text-align:center; padding:2px; color: #fff; font-weight: 600;">' +
					label +
					'<br>' +
					Math.round(series.percent) + '%</div>'
			}
			//查找中转站的地理位置
//			function selectTransferstation(){
//				$.ajax({
//				type: "post", //请求方式
//				async: true, //是否异步
//				xhrFields: {
//					withCredentials: true
//				},
//				crossDomain: true,
//				url: "http://localhost:8073/selectTransferstation",
//				dataType: "json", //跨域json请求一定是jsonp
//				// jsonp: "callback", //跨域请求的参数名，默认是callback
//				//jsonpCallback:"successCallback",    //自定义跨域参数值，回调函数名也是一样，默认为jQuery自动生成的字符串
//				data: {sid: 4}, //请求参数
//				beforeSend: function() {
//					//请求前的处理
//					//alert("请求前")
//				},
//				success: function(data) {
//					alert(data)
//				}
//
//				});
//			}
//			selectTransferstation();
            var sz1=new Array();
			//查看需中转货物
			function goodsRequiringTransit(){
				$("#txt").empty()
				$("#txt").append("<input type='checkbox' onclick='bu1isToenablethe()' id='goodsRequiringTransit'/> 需中转货物");
				$.ajax({
				type: "post", //请求方式
				async: true, //是否异步
				xhrFields: {
					withCredentials: true
				},
				crossDomain: true,
				url: "http://localhost:8073/goodsRequiringTransit",
				dataType: "json", //跨域json请求一定是jsonp
				// jsonp: "callback", //跨域请求的参数名，默认是callback
				//jsonpCallback:"successCallback",    //自定义跨域参数值，回调函数名也是一样，默认为jQuery自动生成的字符串
				data: {sid:$.cookie("sid"),query:"goodsRequiringTransit"}, //请求参数
				beforeSend: function() {
					//请求前的处理
					//alert("请求前")
				},
				success: function(data) {
					$("#windows").empty()
					$.each(data, function(i,d) {
						$("#windows").append(" <tr>" +
							"<td><a href='#' onclick='getSasid("+d.sasid+")'>OR9842"+d.sasid+"</a></td>" +
							"<td>"+d.starting+"</td>" +
							"<td><span class='badge badge-success'>"+d.issignforit+"</span></td>" +
							" <td>" +
							" <div class='sparkbar' data-color='#00a65a' data-height='20'>"+d.cargoinformation+"</div>" +
							"</td>" +
							"<td>"+d.surplusdistance+"M</td>" +
							"</tr>");
							sz1.push(d.sasid);
					});
				  }
				});
			}
			var sz2= new Array();
			//查看需装运货物
			function goodsToBeShipped(){
				$("#txt").empty()
				$("#txt").append("<input type='checkbox' onclick='bu2isToenablethe()' id='goodsToBeShipped' /> 需装运货物");
				$.ajax({
				type: "post", //请求方式
				async: true, //是否异步
				xhrFields: {
					withCredentials: true
				},
				crossDomain: true,
				url: "http://localhost:8073/goodsToBeShipped",
				dataType: "json", //跨域json请求一定是jsonp
				// jsonp: "callback", //跨域请求的参数名，默认是callback
				//jsonpCallback:"successCallback",    //自定义跨域参数值，回调函数名也是一样，默认为jQuery自动生成的字符串
				data: {sid: $.cookie("sid"),query:"goodsToBeShipped"}, //请求参数
				beforeSend: function() {
					//请求前的处理
					//alert("请求前")
				},
				success: function(data) {
					$("#windows").empty()
					$.each(data, function(i,d) {
						$("#windows").append(" <tr>" +
							"<td><a href='#' onclick='getSasid("+d.sasid+")'>OR9842"+d.sasid+"</a></td>" +
							"<td>"+d.starting+"</td>" +
							"<td><span class='badge badge-success'>"+d.issignforit+"</span></td>" +
							" <td>" +
							" <div class='sparkbar' data-color='#00a65a' data-height='20'>"+d.cargoinformation+"</div>" +
							"</td>" +
							"<td>"+d.surplusdistance+"M</td>" +
							"</tr>");
							sz2.push(d.sasid);
					});
				  }
				});
			}
			//查找全部
			function whole(){
				$("#txt").empty()
				$("#txt").append("仓库内所有货物信息");
				$.ajax({
				type: "post", //请求方式
				async: true, //是否异步
				xhrFields: {
					withCredentials: true
				},
				crossDomain: true,
				url: "http://localhost:8073/whole",
				dataType: "json", //跨域json请求一定是jsonp
				// jsonp: "callback", //跨域请求的参数名，默认是callback
				//jsonpCallback:"successCallback",    //自定义跨域参数值，回调函数名也是一样，默认为jQuery自动生成的字符串
				data: {sid: $.cookie("sid"),query:"whole"}, //请求参数
				beforeSend: function() {
					//请求前的处理
					//alert("请求前")
				},
				success: function(data) {
					$("#windows").empty()
					if(data.length){
						$.each(data, function(i,d) {
						$("#windows").append(" <tr>" +
							"<td><a href='#' onclick='getSasid("+d.sasid+")'>OR9842"+d.sasid+"</a></td>" +
							"<td>"+d.starting+"</td>" +
							"<td><span class='badge badge-success'>"+d.issignforit+"</span></td>" +
							" <td>" +
							" <div class='sparkbar' data-color='#00a65a' data-height='20'>"+d.cargoinformation+"</div>" +
							"</td>" +
							"<td>"+d.surplusdistance+"M</td>" +
							"</tr>");
					});
					}else{
						$("#windows").append(" <tr>" +
							"<td colspan='5'>无数据</td>" +
							"</tr>");
					}
					
				  },complete: function(data) {
				  	    forbiddenButton();
						window.parent.dataFilling();//调用父窗口函数
						//请求完成的处理
						//alert(data)
						// alert("请求完成")
					}
				});
			}
			/*调用父窗口内的函数*/
			function getSasid(sasid){
				window.parent.showMyCart(sasid);
			}
			/*
			 * 禁用按钮
			 */
			function forbiddenButton(){
				$("#bu1").attr("disabled","disabled")
				$("#bu2").attr("disabled","disabled")
			}
			forbiddenButton()
			function  bu1isToenablethe(){
				if($("#goodsRequiringTransit").is(":checked")){
					$("#bu1").removeAttr("disabled")/*启用添加到中转单按钮*/
				}else{
					$("#bu1").attr("disabled","disabled")
				}
				
			}
		    function  bu2isToenablethe(){
				if($("#goodsToBeShipped").is(":checked")){
					$("#bu2").removeAttr("disabled")/*用添加到装运单按钮*/
				}else{
					$("#bu2").attr("disabled","disabled")
				}
			}
			/**
			 * 添加货物到中转单
			 */
			function addTransitofsingle (){
				$.ajax({
				type: "post", //请求方式
				async: true, //是否异步
				xhrFields: {
					withCredentials: true
				},
				crossDomain: true,
				traditional:true,
				url: "http://localhost:8073/addTransitofsingle",
				dataType: "json", //跨域json请求一定是jsonp
				// jsonp: "callback", //跨域请求的参数名，默认是callback
				//jsonpCallback:"successCallback",    //自定义跨域参数值，回调函数名也是一样，默认为jQuery自动生成的字符串
				data: {sid: $.cookie("sid"),query:sz1}, //请求参数
				beforeSend: function() {
					
				},
				success: function(data) {
					
				  },complete: function(data) {
						//请求完成的处理
						//alert(data)
						// alert("请求完成")
						sz1=null;
						whole();
					},
				});
			}
			/**
			 * 添加货物到装运单
			 */
			function addTloading (){
				$.ajax({
				type: "post", //请求方式
				async: true, //是否异步
				xhrFields: {
					withCredentials: true
				},
				crossDomain: true,
				traditional:true,
				url: "http://localhost:8073/addTloading",
				dataType: "json", //跨域json请求一定是jsonp
				// jsonp: "callback", //跨域请求的参数名，默认是callback
				//jsonpCallback:"successCallback",    //自定义跨域参数值，回调函数名也是一样，默认为jQuery自动生成的字符串
				data: {sid: $.cookie("sid"),query:sz2}, //请求参数
				beforeSend: function() {
					
				},
				success: function(data) {
					
				  },complete: function(data) {
						//请求完成的处理
						//alert(data)
						// alert("请求完成")
						sz2=null;
						whole();
					},
				});
			}
			whole();
		</script>
	</body>

</html>